# -*- coding: utf-8 -*-
"""
@Time    : 2024/8/28 14:53 
@Author  : ZhangShenao 
@File    : model_api.py 
@Desc    : 调用OpenAI的Model相关API

API文档: https://platform.openai.com/docs/api-reference/models/list
"""
import os

import dotenv
from openai import OpenAI

# 加载环境变量
dotenv.load_dotenv()

# 创建OpenAI客户端
client = OpenAI(base_url=os.getenv("OPENAI_API_BASE"))

# 列出所有可用的模型
models = client.models.list()
model_ids = [model.id for model in models.data]
print(f"模型ID列表: {model_ids}")

# 获取单个模型信息
gpt_4o_mini = client.models.retrieve(model="gpt-4o-mini")
print(f"gpt_4o_mini: {gpt_4o_mini}")
